<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生成绩管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"/>
    <script src="${pageContext.request.contextPath}/back/statics/js/jquery-1.8.3.min.js"></script>
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<script>




   $(document).ready(function(){
        if("${ident}"=="student"){
            $("#add").hide();
            $("#caozuo").hide();
            $("#cz").hide();
        }else if("${ident}"=="teacher"){
            $("#tz").hide();
        }
    });


    // 修改表单
    function change_grade(gradeid)
    {


        var coursecredit=$.trim($("#coursecredit2").val());
        var  score=$.trim($("#score2").val());
        var gradeid=gradeid;




        $.ajax(
            {
                url: "${pageContext.request.contextPath}/grade/changeGrade",
                data:{coursecredit:coursecredit,gradeid:gradeid,score:score},
                type: "post",

                beforeSend:function()
                {
                     $("#tip2").html("<span style='color:blue'>正在处理...</span>");
                    return true;
                },
                success:function(data)
                {
                       alert("成绩修改成功")
                        location.reload();
                },
                error:function()
                {
                    alert('请求出错');
                },
                complete:function()
                {
                    // $('#tips').hide();
                }
            });

        return false;
    }



    // 修改模块
    function add_grade(gradeid)
    {



         var usual=$.trim($("#usual").val());
         var middle=$.trim($("#middle").val());
         var finalScore=$.trim($("#final").val());
         var graid=gradeid;



        $.ajax(
            {
                url: "${pageContext.request.contextPath}/grade/writeScore",
               // data:{form_data:form_data,act:act},
               data:{gradeid:graid,usual:usual,middle:middle,finalScore:finalScore},
                type: "post",
                beforeSend:function()
                {
                    $("#tip").html("<span style='color:blue'>正在处理...</span>");
                    return true;
                },
                success:function(data)
                {
                       var msg = "修改";
                        $("#tip").html("<span style='color:blueviolet'>" +msg+ "成功！</span>");
                        alert("成绩编号为："+gradeid+"的信息"+msg + "成功");
                        location.reload();

                },
                error:function()
                {
                    alert('请求出错');
                },
                complete:function()
                {
                    $('#acting_tips').hide();
                }
            });

        return false;
    }



    $(function () { $('#addUserModal').on('hide.bs.modal', function () {
        // 关闭时清空edit状态为add
        $("#act").val("add");
        location.reload();
    })
    });

</script>
<body>

<div class="container-fluid">

    <%--标题--%>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4">
            <h1 class="text-center">学生成绩管理</h1>
        </div>
    </div>

    <%--搜索条件--%>
    <div class="row" style="margin:20px 0px;">
        <div class="col-sm-10 col-sm-offset-1 text-center">
            <form class="form-inline" action="${pageContext.request.contextPath}/grade/listGrades" method="post">
                <div class="form-group">
                    <select class="form-control" name="searchCol" id="searchCol">

                        <option value="c.coursename"
                                <c:if test="${searchCol=='c.coursename'}">
                                    selected
                                </c:if>
                        >课程
                        </option>
                        <option value="c.term"
                                <c:if test="${searchCol=='c.term'}">
                                    selected
                                </c:if>
                        >学期
                        </option>
                        <option value="s.stuname"
                                <c:if test="${searchCol=='s.stuname'}">
                                    selected
                                </c:if>
                        >姓名
                        </option>

                    </select>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="searchValue" value="${searchValue}"
                           style="width:500px;" id="searchValue"
                           placeholder="请输入对应的搜索关键词">
                </div>
                <button type="submit" class="btn btn-primary">查询</button>
            </form>
        </div>
    </div>


    <%--表格--%>
    <div class="row" style="height: 600px; margin-top: 40px">
        <div class="col-sm-12">
            <c:if test="${grades.size()==0}">
                <h1 class="text-center text-info">还没有任何数据~~~</h1>
            </c:if>

            <c:if test="${grades.size()>0}">
                <table class="table table-striped table-hover table-bordered">
                    <tr>
                        <th>姓名</th>
                        <th>学号</th>
                        <th>课程名</th>
                        <th>分数</th>
                        <th>学分</th>
                        <th>学期</th>
                        <th>平时成绩</th>
                        <th>期中成绩</th>
                        <th>期末成绩</th>
                        <th id="cz">操作</th>
                    </tr>
                        <%--循环域中的学生集合。展示数据--%>
                    <c:forEach items="${grades}" var="grade">

                        <tr>
                            <td>${grade.stuname}</td>
                            <td>${grade.studentid}</td>
                            <td>${grade.coursename}</td>
                            <td>${grade.score}</td>
                            <td>${grade.coursecredit}</td>
                            <td>${grade.term}</td>
                            <td>${grade.usualperformance}</td>
                           <td>${grade.middleexam}</td>
                            <td>${grade.finalexam}</td>
                            <td id="caozuo"> <button type="button" class="btn btn-info" data-toggle="modal"  data-target="#addUserModal2">修改</button>
                                <a id="tz" href="${pageContext.request.contextPath}/grade/deleteGrade?gd=${grade.studentid}" class="btn btn-danger">删除</a>
                                <button id="add" class="btn btn-success"  type="button" data-toggle="modal"  data-target="#addUserModal">录入成绩</button>

                                <!-- 模态框 -->
                            <!-- 模态框 -->
                            <!-- 模态框 -->
                            <form method="post" action="" class="form-horizontal" role="form" id="form_data" onsubmit="return add_grade(${grade.gradeid})" style="margin: 20px;">
                                <div class="modal fade" id="addUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                                    &times;
                                                </button>
                                                <h4 class="modal-title" id="myModalLabel">
                                                    录入分数
                                                </h4>
                                            </div>
                                            <div class="modal-body">
                                                <form class="form-horizontal" role="form" title="${grade.studentid}">
                                                    <div class="form-group">
                                                        <label for="usual" class="col-sm-3 control-label">平时成绩</label>
                                                        <div class="col-sm-9">
                                                            <input type="text" class="form-control" id="usual" name="usual" value=""
                                                                   placeholder="请输入平时成绩">
                                                        </div>
                                                    </div>


                                                    <div class="form-group">
                                                        <label for="middle" class="col-sm-3 control-label">期中成绩</label>
                                                        <div class="col-sm-9">
                                                            <input type="text" class="form-control" name="middle" value="" id="middle"
                                                                   placeholder="请输入期中成绩" >
                                                        </div>
                                                    </div>



                                                    <div class="form-group">
                                                        <label for="final" class="col-sm-3 control-label">期末成绩</label>
                                                        <div class="col-sm-9">
                                                            <input type="text" class="form-control" name="final"  id="final"
                                                                   placeholder="请输入期末成绩" >
                                                        </div>
                                                    </div>


                                                </form>


                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                                </button>
                                                <button type="submit" class="btn btn-primary">
                                                    提交
                                                </button><span id="tip"> </span>
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal -->
                                </div>
                            </form>


                        </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>
        </div>



    </div>

    <%--分页工具栏--%>
    <div class="row" style="margin-top: -300px">
        <div class="col-sm-12 text-center">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li>
                        <c:if test="${page>1}">
                            <a href="${pageContext.request.contextPath}/grade/listGrades?page=${page-1}&searchCol=${searchCol}&searchValue=${searchValue}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </c:if>
                    </li>
                    <c:forEach begin="1" step="1" end="${pages}" varStatus="state">
                        <li><a href="${pageContext.request.contextPath}/grade/listGrades?page=${state.count}&searchCol=${searchCol}&searchValue=${searchValue}">${state.count}</a></li>
                    </c:forEach>

                    <li>
                        <c:if test="${page<pages}">
                            <a href="${pageContext.request.contextPath}/grade/listGrades?page=${page+1}&searchCol=${searchCol}&searchValue=${searchValue}" aria-label="Previous">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </c:if>

                    </li>
                </ul>
            </nav>
        </div>
    </div>


        <!-- 模态框（Modal2） -->
        <form method="post" action="" class="form-horizontal" role="form" id="form_data2" onsubmit="return  change_grade(${grade.gradeid})" style="margin: 20px;">
            <div class="modal fade" id="addUserModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                &times;
                            </button>
                            <h4 class="modal-title" id="mModalLabel">
                                修改成绩
                            </h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal" role="form" >
                                <div class="form-group">
                                    <label for="coursecredit2" class="col-sm-3 control-label">学分</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" value="${student.coursecredit}" id="coursecredit2" name="coursecredit2"
                                               placeholder="请输入学分">
                                    </div>
                                </div>





                                <div class="form-group">
                                    <label for="score2" class="col-sm-3 control-label">分数</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="score"  value="${student.score}" id="score2"
                                               placeholder="请输入分数">
                                    </div>
                                </div>


                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                            </button>
                            <button type="submit" class="btn btn-primary">
                                提交
                            </button><span id="tip2"> </span>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
        </form>


</div>

</body>
</html>